﻿using Autofac;
using Autofac.Configuration;
using Serilog;
using Microsoft.Extensions.Configuration;
using Elasticsearch.Synchronize.Job.Job;

namespace Elasticsearch.Synchronize.Job
{
    public class ServiceDependencyModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            // 注册autofac.json
            var config = new ConfigurationBuilder();
            // config.AddJsonFile comes from Microsoft.Extensions.Configuration.Json
            // config.AddXmlFile comes from Microsoft.Extensions.Configuration.Xml
            config.AddJsonFile("autofac.json");

            // Register the ConfigurationModule with Autofac.
            var module = new ConfigurationModule(config.Build());
            builder.RegisterModule(module);

            builder.RegisterAssemblyTypes(this.ThisAssembly)
                .AsClosedTypesOf(typeof(BaseProcessor<>)).AsSelf().SingleInstance();

            Log.Logger.Information("注入成功了");
        }
    }
}